import 'package:flutter/material.dart';
import 'package:net_store/Entities/Product.dart';
import 'package:net_store/Pages/ProductDetailsPage.dart';
import 'package:net_store/Widgets/SearchButton.dart';

class ProductViewPage extends StatefulWidget {
  List<Product> products;

  ProductViewPage(this.products);

  @override
  State<StatefulWidget> createState() => _ProductViewPageState();
}

class _ProductViewPageState extends State<ProductViewPage> {
  @override
  Widget build(BuildContext context) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Color(0xff288B2B),
          title: SearchButton(
            onTap: (){
              Navigator.of(context).pop();
            },
          ),
          centerTitle: true,
        ),
        body: ListView(
          children: widget.products.map((product) => buildItem(product)).toList(),
        ),
      ),
    );
  }

  Widget buildItem(Product product){
    return InkWell(
      child: Container(
        height: 120.0,
        margin: EdgeInsets.all(20.0),
        padding: EdgeInsets.only(right: 70.0),
        child: Stack(
          children: <Widget>[
            Container(
                padding: EdgeInsets.only(right: 55.0),
                width: double.infinity,
                decoration: BoxDecoration(
                  color: Color(0xfff0f0f0),
                  borderRadius: BorderRadius.only(
                      topRight: Radius.circular(8.0),
                      bottomRight: Radius.circular(8.0),
                      bottomLeft: Radius.circular(20.0),
                      topLeft: Radius.circular(20.0)
                  ),
                  boxShadow: [
                    BoxShadow(color: Colors.black12, blurRadius: 2.0, spreadRadius: 2.0, offset: Offset(0.0, 0.0))
                  ],
                ),
                child: Padding(
                  padding: EdgeInsets.all(10.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Expanded(child: Text(product.name, style: TextStyle(fontSize: 17.0, fontWeight: FontWeight.bold),),),
                          Text(product.exportprice.toString(), style: TextStyle(color: Colors.deepOrange, fontSize: 22.0, fontWeight: FontWeight.bold),),
                        ],
                      ),
                      SizedBox(height: 5.0,),
                      Text(product.describe),
                    ],
                  ),
                )
            ),
            Align(
              alignment: Alignment(1.0, 0.0),
              child: Transform.translate(
                offset: Offset(50.0, 0.0),
                child: Hero(
                  tag: product.guid,
                  child: CircleAvatar(
                    backgroundImage: NetworkImage(product.images.first),
                    radius: 50.0,
                  ),
                )
              ),
            ),
            Align(
              alignment: Alignment(-1.0, 1.0),
              child: Padding(
                padding: EdgeInsets.all(10.0),
                child: Icon(Icons.favorite_border),
              ),
            ),
          ],
        ),
      ),
      onTap: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProductDetailsPage(product)));
      },
    );
  }
}


